/*
 * @Author: 杨小灿jian308@qq.com
 * @Date: 2023-05-18 10:47:01
 * @LastEditors: 杨小灿jian308@qq.com
 * @LastEditTime: 2023-05-18 11:51:26
 */
package utils

import (
	"runtime"
	"strconv"

	"gitee.com/jieyang/go/clog"
)

// 产生panic时的调用栈打印
func PrintPanicStack(extras ...interface{}) {
	if x := recover(); x != nil {
		clog.Error().Any("recover", x).Send()
		i := 0 //
		funcName, file, line, ok := runtime.Caller(i)
		for ok {
			clog.Error().Int("frame", i).Str("func", runtime.FuncForPC(funcName).Name()).Msg(file + ":" + strconv.Itoa(line))
			i++
			funcName, file, line, ok = runtime.Caller(i)
		}
		for k := range extras {
			clog.Error().Int("extras", k).Any("=>", extras[k])
		}
	}
}
